package com.ybxx.system.service.impl;


import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.system.SystemConstants;
import com.ybxx.system.dao.UserDao;
import com.ybxx.system.model.User;
import com.ybxx.system.service.UserService;

public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

	public UserDao userDao;
	public UserServiceImpl(UserDao dao) {
		
		super(dao);
		this.userDao = dao;
	}

	public User login(String loginName){
		String hql = "from User u where u.loginid='"+loginName+"' and u.state='"+SystemConstants.ENABLE+"'";
		User user = (User)this.userDao.findUnique(hql, null);
		return user;
	}
	
	public List<User> queryPage(QueryFilter filter,String name){
		List<User> users=null;
		String hql="from User u";
		if(StringUtils.isNotEmpty(name)){
			hql+=" where u.name like '%"+name+"%'";
		}
		hql+=" order by u.state,u.loginid";
		users=this.userDao.findByHql(hql, null, filter.getPagingBean());
		return users;
	}
	public void saveUserPermission(User user){
		String sql="delete from tbl_system_datarights where loginid='"+user.getLoginid()+"'";
		userDao.excuteSql(sql);
		super.save(user);
	}
}
